package com.lxh.student.common;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ResponseResult<T> {

    private int code;//设置响应状态 1成功 0失败
    private String msg;//响应的信息
    private T data;//响应的数据

    /* 设置通用的返回方法 */
    /* 成功响应方法 */
    public static ResponseResult createSuccess() {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getComment(), null);
    }
    public static <T> ResponseResult<T> createSuccess(T data) {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getComment(), data);
    }
    public static ResponseResult createSuccess(String msg) {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), msg, null);
    }
    public static <T> ResponseResult<T> createSuccess(String msg, T data) {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), msg, data);
    }

    /* 失败响应方法 */
    public static ResponseResult createFail() {
        return new ResponseResult(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getComment(), null);
    }
    public static <T> ResponseResult<T> createFail(T data) {
        return new ResponseResult(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getComment(), data);
    }
    public static ResponseResult createFail(String msg) {
        return new ResponseResult(ResponseCode.FAIL.getCode(), msg, null);
    }
    public static <T> ResponseResult<T> createFail(String msg, T data) {
        return new ResponseResult(ResponseCode.FAIL.getCode(), msg, data);
    }

    /* 通用自定义参数方法 */
    public static <T> ResponseResult<T> createLoginResponse(int code, String msg, T data) {
        return new ResponseResult(code, msg, data);
    }
}
